<?php
class Vaga extends AppModel {
	var $name = 'Vaga';
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $belongsTo = array(
		'Empresa' => array(
			'className' => 'Empresa',
			'foreignKey' => 'empresa_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Paise' => array(
			'className' => 'Paise',
			'foreignKey' => 'paise_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Provincia' => array(
			'className' => 'Provincia',
			'foreignKey' => 'provincia_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Distrito' => array(
			'className' => 'Distrito',
			'foreignKey' => 'distrito_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'TempoExperiencia' => array(
			'className' => 'TempoExperiencia',
			'foreignKey' => 'tempo_experiencia_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

	var $hasAndBelongsToMany = array(
		'Area' => array(
			'className' => 'Area',
			'joinTable' => 'areas_vagas',
			'foreignKey' => 'vaga_id',
			'associationForeignKey' => 'area_id',
			'unique' => true,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'finderQuery' => '',
			'deleteQuery' => '',
			'insertQuery' => ''
		),
		'TipoEmprego' => array(
			'className' => 'TipoEmprego',
			'joinTable' => 'tipo_empregos_vagas',
			'foreignKey' => 'vaga_id',
			'associationForeignKey' => 'tipo_emprego_id',
			'unique' => true,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'finderQuery' => '',
			'deleteQuery' => '',
			'insertQuery' => ''
		)
	);
	
	function getRecentVagas($limit=5){
		$today = date('Y-m-d');
		$vagas = $this->find('all',array('conditions'=>array('data_publicacao <='=>$today,'data_limite >='=>$today),null,'order'=>'Vaga.id DESC','limit'=>$limit));
		
		return $vagas;
	}

}
